
#ifndef etl_calendar_h
#define etl_calendar_h

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "etl_string.h"

namespace etl
{

class etl_calendar
{
public:
    enum etl_calendar_components
    {
        SECOND,
        MINUTE,
        HOUR,
        MONTH_DAY,
        MONTH_WEEK,
        MONTH,
        YEAR,
        YEAR_WEEK,
        WEEK_DAY,
        YEAR_DAY
    };

    enum etl_calendar_weekdays
    {
        SUNDAY = 0,
        MONDAY = 1,
        TUESDAY = 2,
        WEDNESDAY = 3,
        THURSDAY = 4,
        FRIDAY = 5,
        SATURDAY = 6      
    };

    etl_calendar();
    etl_calendar( time_t then );
    etl_calendar( struct tm* bdt );
    etl_calendar( const etl_calendar& obj );
    etl_calendar( etl::etl_string orig, etl::etl_string formatStr);

    virtual ~etl_calendar();

    etl_calendar& operator = ( const etl_calendar& obj );

    etl_calendar& operator = ( const time_t& then );

    bool operator == ( const etl_calendar& obj );

    bool operator < ( const etl_calendar& obj );
    bool operator <= ( const etl_calendar& obj );
    bool operator > ( const etl_calendar& obj );
    bool operator >= ( const etl_calendar& obj );

    int get_component_max_value( etl_calendar_components type );

    int inc( etl_calendar_components type, int interval );
    int dec( etl_calendar_components type, int interval );

    int get_component( etl_calendar_components type );
    int set_component( etl_calendar_components type, int val );

    time_t get_epoch_time();

private:
    etl_calendar& copy( const etl_calendar& obj );

    int break_down( struct tm* bdt );
    int break_down( struct tm* bdt, time_t then );

    int build_up( struct tm* bdt );
    int build_up( struct tm* bdt, time_t* then );
 
    time_t epoch_time;
};

}

#endif
